package com.fenqing.leetcode.code.t700_800;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.Arrays;
import java.util.Stack;

public class Topic739 extends Topic {
    /**
     * 构造器
     *
     * @param input 输入
     */
    public Topic739(String input) {
        super(input);
    }

    @Execute
    public int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> indexStack = new Stack<>();
        int[] res = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            while (!indexStack.isEmpty()){
                Integer peek = indexStack.peek();
                int temperature = temperatures[peek];
                if (temperature < temperatures[i]) {
                    res[peek] = i - peek;
                    indexStack.pop();
                } else {
                    break;
                }
            }
            indexStack.push(i);
        }
        return res;
    }

    public static void main(String[] args) {
        int[] ints = new Topic739("[73,74,75,71,69,72,76,73]").run();
        System.out.println(Arrays.toString(ints));
    }
}
